Page({
  data: {
    complaint: null,
    complaintId: null
  },

  onLoad: function(options) {
    this.setData({
      complaintId: options.id
    });
    this.loadComplaintDetail();
  },

  loadComplaintDetail: function() {
    const app = getApp();
    app.request({
      url: `/complaints/${this.data.complaintId}/`,
      method: 'GET',
      success: (res) => {
        if (res.statusCode === 200) {
          this.setData({
            complaint: res.data
          });
        } else {
          wx.showToast({
            title: '获取投诉详情失败',
            icon: 'none'
          });
        }
      },
      fail: () => {
        wx.showToast({
          title: '网络请求失败',
          icon: 'none'
        });
      }
    });
  },

  goToOrderDetail: function() {
    if (this.data.complaint && this.data.complaint.order_id) {
      wx.navigateTo({
        url: `/pages/customer/orderDetail?id=${this.data.complaint.order_id}`
      });
    }
  },

  onPullDownRefresh: function() {
    this.loadComplaintDetail();
    wx.stopPullDownRefresh();
  }
});